//package org.gg.boom.modules.ai;
//
//import com.alibaba.dashscope.common.Message;
//import lombok.RequiredArgsConstructor;
//import org.springframework.ai.chat.ChatClient;
//import org.springframework.ai.chat.StreamingChatClient;
//import org.springframework.ai.chat.prompt.Prompt;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import reactor.core.publisher.Flux;
//
//import java.util.Map;
//
///**
// * chat controller
// */
//@RestController
//@RequestMapping("/ai")
//@RequiredArgsConstructor
//public class ChatController {
//
//    private final ChatClient chatClient;
//
//    private final StreamingChatClient streamingChatClient;
//
//    @GetMapping("/chat")
//    public String chat(String message) {
//        StringBuilder fullContent = new StringBuilder();
//        streamingChatClient.stream(new Prompt(message))
//                .flatMap(chatResp -> Flux.fromIterable(chatResp.getResults()))
//                .map(context -> context.getOutput().getContent())
//                .doOnNext(fullContent::append)
//                .last()
//                .map(lastContent -> Map.of(message, fullContent.toString()))
//                .block();
//        return fullContent.toString();
//    }
//}
